#include <iostream>

using namespace std;
const int N=60;
int maxn,minn,total;
int n;
int a[N];
bool dfs(int limit,int count,int sum,int cur)
{
	if(count==total/limit)
	{
		return true;
	}
	if(sum>limit)
		return false;
	if(sum==limit)
	{
		return dfs(limit,count+1,0,maxn);
	}
	if(sum+minn>limit)
		return false;
	for(int i=cur;i>=minn;i--)
	{
		if(a[i] && sum+i<=limit)
		{
			a[i]--;
			if(dfs(limit,count,sum+i,i))
			{
				return true;
			}
			a[i]++;
			if(sum==0 || sum+i==limit)
			{
				return false;
			}
		}
	}
	return false;
}
int main()
{
	cin>>n;
	total=0;
	minn=0x3f;
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		total+=t;
		a[t]++;
		maxn=max(maxn,t);
		minn=min(minn,t);
	}
	int ret=-1;
	for(int i=maxn;i<=total;i++)
	{
		if(total%i)
			continue;
		if(dfs(i,0,0,maxn))
		{
			ret=i;
			break;
		}
	}
	cout<<ret<<endl;
	return 0;
}
